package com.shop.front.dao.pink;


import com.shop.jpa.BaseSQLDao;
import com.shop.jpa.support.QuerySQL;
import com.shop.front.vo.pink.StorePinkVo;
import com.shop.web.context.WebContext;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Repository;

@Repository
public class StorePinkSQLDao extends BaseSQLDao {

    /**
     * 分页查询推荐用户列表
     *
     * @param userId
     * @return
     */
    public Page<StorePinkVo> pagePink(Long userId) {
        StringBuffer field = new StringBuffer("pink.*, sp.store_name, spav.suk, spav.image");
        String from = "t_store_pink pink left join t_store_product sp on pink.product_id = sp.id left join t_store_product_attr_value spav on pink.product_attr_value_id = spav.id";
        String order = "pink.id desc";
        QuerySQL qs = new QuerySQL(WebContext.getPageNo(), WebContext.getPageSize(), field.toString(), from, order);
        qs.addWhereWithoutParams("pink.is_deleted = 0");
        qs.addWhereWithoutParams("pink.status not in (0)");
        qs.addWhereEq("pink.uid", userId);
        return this.page(qs, StorePinkVo.class);
    }


    /**
     * 查询拼团历史
     *
     * @param userId
     * @return
     */
    public Page<StorePinkVo> pagePinkHistory(Long userId) {
        StringBuffer field = new StringBuffer("pink.*, sp.store_name, spav.suk, spav.image");
        String from = "t_store_pink_history pink left join t_store_product sp on pink.product_id = sp.id left join t_store_product_attr_value spav on pink.product_attr_value_id = spav.id";
        String order = "pink.id desc";
        QuerySQL qs = new QuerySQL(WebContext.getPageNo(), WebContext.getPageSize(), field.toString(), from, order);
        qs.addWhereWithoutParams("pink.is_deleted = 0");
        qs.addWhereWithoutParams("pink.status not in (0)");
        qs.addWhereEq("pink.uid", userId);
        return this.page(qs, StorePinkVo.class);
    }

}
